package cn.jiyun.manage.product.controller;

import cn.jiyun.common.vo.CommonResult;
import cn.jiyun.manage.product.config.AliyunOSSClientUtil;
import cn.jiyun.manage.product.feign.ProductFenilei;
import cn.jiyun.manage.product.service.ManageService;
import cn.jiyun.model.Base;
import cn.jiyun.model.Spercs;
import cn.jiyun.model.dto.ManageDto;
import cn.jiyun.model.vo.BaseOtherSpecsVo;
import cn.jiyun.model.vo.ManageBaseSpercsVo;
import cn.jiyun.model.vo.ManageListVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/manage")
public class ManageController {
    @Autowired
    private ManageService manageService;
    @Autowired
    private AliyunOSSClientUtil aliyunOSSClientUtil;
   @PostMapping("/findAdd")
    public CommonResult findAdd(@RequestBody ManageDto manageDto){
     return   manageService.findAdd(manageDto);
   }
   @GetMapping("/findAll")
    public CommonResult findAll(){
       List<ManageListVo> manageListVoPage=manageService.findAll();
     return   CommonResult.success(manageListVoPage);
   }
    @RequestMapping("/upload")
    public  String uploader( MultipartFile file) throws Exception {
        String s = aliyunOSSClientUtil.uploadImg2Oss(file);
        String imgUrl = aliyunOSSClientUtil.getImgUrl(s);
//    String url = aliyunOSSClientUtil.getUrl(s);
        return imgUrl;
    }
    @GetMapping("/manageFeign/{id}")
    public Base manageFeign(@PathVariable Integer id){
        Base byId = manageService.manageFeign(id);
        return byId;
    }
    @GetMapping("/findByidBase/{id}")
    public List<Base> findByidBase(@PathVariable Integer id){
        List<Base> byId = manageService.findByidBase(id);
        return byId;
    }
    @GetMapping("/specsFeign/{id}")
    public Spercs specsFeign(@PathVariable Integer id){
        Spercs byId = manageService.specsFeign(id);
        return byId;
    }
    @GetMapping("/specsbaseFeign/{baseid}")
    public Spercs specsbaseFeign(@PathVariable Integer baseid){
        Spercs byId = manageService.specsbaseFeign(baseid);
        return byId;
    }
    @GetMapping("/baseFeign")
    public List<BaseOtherSpecsVo> baseFeign(){
        List<BaseOtherSpecsVo>  baseList= manageService.baseFeign();
        return baseList;
    }
    @GetMapping("/findAllmanage")
    public  CommonResult findAllmanage(){
     List<ManageBaseSpercsVo>  baseList= manageService.findAllmanage();
     return CommonResult.success(baseList);
    }

}
